import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:industry_net/base/common/util.dart';
import 'package:industry_net/base/component/component.dart';
import 'package:industry_net/pages/home/app_man/controller.dart';
import '../app_more/models/app_model.dart';

class AppManCell extends StatelessWidget {
  AppManCell({Key? key, required this.mod, required this.isAdd})
      : super(key: key);
  final AppModel mod;
  final bool isAdd;
  final controller = Get.find<AppManController>();
  @override
  Widget build(BuildContext context) {
    return Container(
      key: mod.key,
      padding: EdgeInsets.only(top: 10.w, bottom: 10.w),
      margin: EdgeInsets.fromLTRB(gap12, 0, gap12, gap12),
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(circle4)),
      child: Padding(
        padding: EdgeInsets.symmetric(horizontal: gap12),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              mod.title,
              style: pfSCStyle(color: ColorsUtil.title, fontSize: font16),
            ),
            SizedBox(
              height: gap10,
            ),
            Wrap(
              runSpacing: 10.w,
              children: mod.items
                  .asMap()
                  .map((key, value) => MapEntry(
                        key,
                        MenuItemView(
                          onTap: () {
                            controller.actionItem(key, mod.items[key], isAdd);
                          },
                          width: (Get.width - 4 * gap12) / 5,
                          icon: SizedBox(
                            width: 40.r,
                            height: 40.r,
                            child: Stack(
                              children: [
                                Positioned(
                                  right: 6.r,
                                  height: 30.r,
                                  width: 30.r,
                                  child: loadImage(
                                      url: value.icon, fit: BoxFit.contain),
                                ),
                                Positioned(
                                  right: 0,
                                  child: Icon(
                                    isAdd
                                        ? IconUtil.add_bg_circle
                                        : IconUtil.delete_bg_circle,
                                    size: 15.r,
                                    color: isAdd
                                        ? ColorsUtil.green
                                        : const Color(0xffc9c9c9),
                                  ),
                                )
                              ],
                            ),
                          ),
                          title: Text(
                            value.name,
                            style: pfMediumStyle(
                                color: ColorsUtil.title, fontSize: font12),
                          ),
                        ),
                      ))
                  .values
                  .toList(),
            )
          ],
        ),
      ),
    );
  }
}
